<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class News extends CI_Controller {

    function __construct(){
        parent::__construct();
        $this->load->model('news_model', 'n');
    }

    function index(){
        $this->category();
    }

    function category($id = 0){
        $id = intval($id);
        $condition = array('delete_flag' => UNDELETE_FLAG, 'active_flag' => ACTIVE_FLAG, 'draft' => UNACTIVE_FLAG);
        if ($id != 0){
            $data['category_info']    = $this->db->where('category_id', $id)->get(TBL_NEWS_CATEGORY)->row();
            $condition['category_id'] = $id;
        }
        $data['current_cat'] = $id;
        $data['result'] = $this->n->order_by('create_date', 'desc')->get_many_by($condition);
        $data['tpl']    = 'news/category';
        $this->load->view('_layout/index', $data);
    }

    function detail($id = 0){
        $data['data'] = $this->n->get_by(array('news_id' => $id));
        $data['more'] = $this->n->limit(10)->order_by('create_date', 'desc')->get_many_by(array('news_id !=' => $id, 'delete_flag' => UNDELETE_FLAG, 'draft' => UNACTIVE_FLAG));
        $data['tpl']    = 'news/detail';
        $this->load->view('_layout/index', $data);
    }
}